import router from "@/router/index";

/**
 * 设置浏览器标题国际化
 * @method const title = useTitle(); ==> title()
 */
export function useTitle() {
  const stores = useConfigStore();
  const { config } = storeToRefs(stores);
  nextTick(() => {
    let webTitle = "";
    let globalTitle = config.value.globalTitle;
    const { path, meta } = router.currentRoute.value;
    if (path === "/login") {
      webTitle = meta.title;
    } else {
      webTitle = router.currentRoute.value.meta.title || "未命名";
    }
    document.title = `${webTitle} - ${globalTitle}` || globalTitle;
  });
}
